{extends file="backend/index.tpl"}
{block name="page-content"}
<script type="text/javascript">
$(document).ready(function(){
	$(".edit_tr").click(function()
	{
		var ID=$(this).attr('id');
		$("#status_"+ID).hide();
		
		$("#status_input_"+ID).show();
	}).change(function()
	{
		var ID=$(this).attr('id');
		var status=$("#status_input_"+ID).val();
		
		var dataString = 'id='+ ID +'&status='+status;
		
		$("#status_"+ID).html('<img src="/truyen/public/backend/img/load.gif" />');
		
		$.ajax({
			type: "POST",
			url: '/truyen/admin/ajax/updatePromotionStatus',
			data: dataString,
			cache: false,
			success: function(html)
			{
				console.log(html);
				$("#status_"+ID).html(status);
			}
		});		
	});
	
	$(".editbox").mouseup(function() {
		return false
	});
	
	$(document).mouseup(function(){
		$(".editbox").hide();
		$(".text").show();
	});

});
</script>

{literal}
<style>
	.editbox
	{
		display:none;
	}
	.editbox
	{
		font-size:14px;
		width: 70px;
		background-color:#ffffcc;
		border:solid 1px #000;
		padding:4px;
	}
	.edit_tr:hover
	{
		background:url(http://localhost/truyen/public/backend/img/edit.png) right no-repeat #80C8E5;
		cursor:pointer;
	}

</style>
{/literal}
<div class="page-header">
    <div class="icon">
        <span class="ico-pen-2"></span>
    </div>
    <h1>QUẢNG CÁO <small>QUẢN LÝ QUẢNG CÁO</small></h1>
</div>
<form id="validate" action="{$base_url}admin/promotion/addPromotion" method="post" enctype="multipart/form-data">
<div class="row-fluid">
    <div class="span6">
        <div class="block">
            <div class="head">
                <h2>Thêm Quảng Cáo</h2>
            </div>
            <div class="data-fluid">
                <div class="row-form">
					<div class="span3">Image</div>
					<div class="span9">
						<div class="input-append file" style="width: 300px;">
                        	<input type="file" name="filename" style="width: 298px;"/>
                            <input type="text"/>
                            <span class="btn">Browse</span>
                        </div> 
					</div>
				</div>
				<div class="row-form">
					<div class="span3">Link</div>
					<div class="span9">
						<input type="text" name="link">
					</div>
				</div>
				<div class="row-form">
					<div class="span3">Position</div>
					<div class="span9">
						<select name="pos" class="select" style="width: 100%;">
							<option value="1">Trang Chủ</option>
							<option value="2">Trang Truyện</option>
						</select>
					</div>
				</div>
				<div class="toolbar bottom tac">
                    <div class="btn-group">
                        <button class="btn btn-info" type="button" onClick="$('#validate').validationEngine('hide');">Ẩn Thông Báo</button>
                        <button class="btn" type="submit" name="submit" id="addBook">Thêm Quảng Cáo</button>
                    </div>
                </div>
			</div>
		</div>
	</div>
	<div class="span6">
        <div class="block">
        	<div class="head">
                <h2></h2>
            </div>
        	 <div class="data-fluid">
				<div class="row-form">
					<div class="span3">Title</div>
					<div class="span9">
						<input type="text" name="title">
					</div>
				</div>
				<div class="row-form">
					<div class="span3">Alt</div>
					<div class="span9">
						<input type="text" name="alt">
					</div>
				</div>
            </div>
        </div>
    </div>
</div>
</form>
<div class="row-fluid">
    <div class="span12">
        <div class="block">
            <div class="head dblue">
                <div class="icon"><span class="ico-layout-9"></span></div>
                <h2>Danh Sách Quảng Cáo</h2>
                <ul class="buttons">
                    <li><a href="#" onClick="source('table_sort_pagination'); return false;">
                        <div class="icon"><span class="ico-info"></span></div>
                    </a></li>
                </ul>
            </div>
            <div class="data-fluid">
                <table class="table lcnp" id="listGame" cellpadding="0" cellspacing="0" width="100%">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Image</th>
                            <th>Link</th>
                            <th>Title</th>
                            <th>Alt</th>
                            <th>Vị Trí</th>
                            <th>Trạng Thái</th>
                            <th width="80" class="TAC">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                    {foreach from=$listPromotion item=promotion}
                        <tr id="{$promotion.id}" class="edit_tr">
                            <td width="5%">{$promotion.id}</td>
                            <td width="10%"><img src="{$base_url}public/frontend/hinh-anh/quang-cao/{$promotion.image}" width="100px"></td>
                            <td width="20%">{$promotion.link}</td>
                            <td width="20%">{$promotion.title}</td>
                            <td width="20%">{$promotion.alt}</td>
                            <td width="10%">{if $promotion.pos eq 1}Trang Chủ{else}Trang Truyện{/if}</td>
                            <td width="10%">
                            	<span id="status_{$promotion.id}" class="text">
                                	{if $promotion.status eq 1}Hiện{else}<span style="color:red">Ẩn</span>{/if}
                           		</span>
                           		<select name="status" class="editbox" id="status_input_{$promotion.id}" style="display: none;">
                               		<option value="1" {if $promotion.status eq 1}Selected{/if}>Hiện</option>
    								<option value="0" {if $promotion.status eq 0}Selected{/if}>Ẩn</option>
    							</select>
                            </td>
                            <td width="10%">
                                <a href="{$base_url}admin/delete-promotion/{$promotion.id}" class="button red" onclick="return confirm('Bạn có muốn xóa tiếp không?')">
                                    <div class="icon"><span class="ico-remove"></span></div>
                                </a>
                            </td>
                        </tr>
                    {/foreach}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{/block}
